package role

import (
	"context"
	"time"

	"go-weixin/app/usercenter/api/internal/svc"
	"go-weixin/app/usercenter/api/internal/types"
	"go-weixin/app/usercenter/rpc/pb/proto/usercenter"

	"github.com/zeromicro/go-zero/core/logx"
)

type RoleUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRoleUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleUpdateLogic {
	return &RoleUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RoleUpdateLogic) RoleUpdate(req *types.RoleUpdateReq) (resp *types.RoleUpdateResp, err error) {
	ctx, cannFunc := context.WithTimeout(context.Background(), 5*time.Second)
	defer cannFunc()
	_, err = l.svcCtx.UserRpc.RoleUpdate(ctx, &usercenter.RoleUpdateReq{
		Id:       req.Id,
		Name:     req.Name,
		Weight:   req.Weight,
		ParentId: req.ParentId,
	})
	return
}
